package com.example.leero.graduation.Util.permisssion;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.support.annotation.CallSuper;
import android.support.v7.app.AlertDialog;

import com.example.leero.graduation.R;


/**
 * Created by jiangwen on 2017/4/4.
 * hjiangwen1@163.com
 */

public abstract class PermissionResultImpl implements PermissionResult {
  private Context mContext;

  public PermissionResultImpl(Context context) {
    mContext = context;

  }

  @CallSuper
  @Override
  public void onDenied() {
    new AlertDialog.Builder(mContext)
            .setMessage("没有权限，无法查看相册。请手动打开权限。")
            .setPositiveButton("去打开", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                openAppSetting();
              }
            })
            .setNegativeButton("取消", null)
            .show();
  }

  private void openAppSetting() {
    Intent intent = new Intent();
    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", mContext.getPackageName(), null);
    intent.setData(uri);
    mContext.startActivity(intent);
  }

}
